<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="">

    <link rel="shortcut icon" href="<!--{eval echo register_static('img/touch-icon-57x57.png');}-->">

    <title>粉粉管理系统</title>

    <!-- Bootstrap core CSS -->
    <link href="<!--{eval echo register_static('css/bootstrap.min.css');}-->" rel="stylesheet">
    <link href="<!--{eval echo register_static('css/bootstrap-reset.css');}-->" rel="stylesheet">

    <!--Animation css-->
    <link href="<!--{eval echo register_static('css/animate.css');}-->" rel="stylesheet">

    <!--Icon-fonts css-->
    <link href="<!--{eval echo register_static('assets/font-awesome/css/font-awesome.css');}-->" rel="stylesheet" />
    <link href="<!--{eval echo register_static('assets/ionicon/css/ionicons.min.css');}-->" rel="stylesheet" />

    <link href="<!--{eval echo register_static('assets/sweet-alert/sweet-alert.min.css');}-->" rel="stylesheet">

    <!-- Plugins css -->
    <link href="<!--{eval echo register_static('assets/modal-effect/css/component.css');}-->" rel="stylesheet">

    <!-- DataTables -->
    <link rel="stylesheet" href="<!--{eval echo register_static('assets/datatables/jquery.dataTables.min.css" rel="stylesheet');}-->" />

    <!-- Custom styles for this template -->
    <link href="<!--{eval echo register_static('css/style.css');}-->" rel="stylesheet">
    <link href="<!--{eval echo register_static('css/helper.css');}-->" rel="stylesheet">

    <!-- My styles for this template -->
    <link href="<!--{eval echo register_static('css/common.css');}-->" rel="stylesheet">
    <link href="<!--{eval echo register_static('assets/timepicker/bootstrap-timepicker.min.css');}-->" rel="stylesheet">
    <link href="<!--{eval echo register_static('assets/timepicker/bootstrap-datepicker.min.css');}-->" rel="stylesheet">

</head>

<body id="mybody">

<!-- Aside Start-->
<!--{template admin_v2/leftside}-->
<!-- Aside Ends-->


<!--Main Content Start -->
<section class="content">

    <!-- Header -->
    <!--{template admin_v2/header}-->
    <!-- Header Ends -->


    <!-- Page Content Start -->
    <!-- ================== -->

    <div class="wraper container-fluid diary-topics">

        <div class="row">
            <div class="col-md-12">
                <div class="panel panel-default" style="overflow: auto;">
                    <div class="panel-heading">
                        <h3 class="panel-title">订单管理测试</h3>
                    </div>
                    <div class="panel-body">
                        <div class="row" style="margin-bottom: 10px">
                            <div class="col-md-9 col-sm-9 col-xs-9">
                                <!-- Search -->
                                <form class="form-inline" role="form">
                                    <div class="form-group m-l-10">
                                        <input type="text" name="uid" class="form-control" id="inputYourText" placeholder="输入UID"></div>
                                    <div class="form-group">
                                        <select class="form-control myChoose" name="code_status" id="yourPayStatus">
                                            <option value="no">支付状态(全部)</option>
                                            <option value="0">未付款</option>
                                            <option value="1">已付款</option>
                                        </select>
                                    </div>
                                    <div class="form-group">
                                        <select class="form-control myChoose" name="business" id="yourPayBusiness">
                                            <option value="no">订单类型(全部)</option>
                                            <option value="0">购买会员</option>
                                            <option value="1">订阅号打赏</option>
                                            <option value="2">购买粉钻</option>
                                            <option value="3">兑换码</option>
                                            <option value="4">礼物兑换收益</option>
                                            <option value="5">提现申请</option>
                                            <option value="6">赠送粉钻</option>
                                        </select>
                                    </div>
                                    <button type="button" id="search" class="btn btn-success m-l-10">点击搜索</button>
                                    <div class="form-group pageCon">

                                    </div>
                                </form>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-md-12 col-sm-12 col-xs-12">
                                <table id="datatable" class="table table-striped table-bordered table-hover">
                                    <thead>
                                    <tr>
                                        <th>uid</th>
                                        <th>订单号</th>
                                        <th>生成时间</th>
                                        <th>支付状态</th>
                                        <th>操作</th>
                                    </tr>
                                    </thead>

                                    <tbody id="tbody">

                                    </tbody>
                                </table>
                            </div>
                        </div>
                        <div class="row" style="margin-top: 15px">
                            <div class="form-group pageCon"></div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

    </div>
    <!-- Page Content Ends -->
    <!-- ================== -->

    <div id="con-close-modal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="display: none;">

    </div><!-- /.modal -->


    <!-- Footer Start -->
    <!--{template admin_v2/footer}-->
    <!-- Footer Ends -->



</section>
<!-- Main Content Ends -->

<!--template start-->
<script type="text/template" id="tableCon">
    {{#.}}
    <tr>
        <td>{{{uid}}}</td>
        <td><label class="label label-success">{{{order_sn}}}</label></td>
        <td><label class="label label-info">{{{dateConvNew create_time}}}</label></td>
        <td>{{{payStatusText pay_status}}}</td>
        <td>
            <div class="btn-group btn-group-sm">
                <button type="button" class="btn btn-info detail" data-id="{{{order_id}}}" data-uid="{{{uid}}}">详情</button>
                <!--加判断条件显示按钮 ：未付款 + 订阅号 + 粉砖兑换礼物-->
                <!--<button type="button" class="btn btn-info update" data-uid="{{{uid}}}" data-id="{{{order_id}}}" >补单</button>-->
                {{{businessAction pay_status business uid order_sn}}}
            </div>
        </td>
    </tr>
    {{/.}}
</script>

<script type="text/template" id="detailModal">
    {{#.}}
    <form>
        <div>
            <table class="table table-bordered">
                <thead>
                <tr>
                    <th width="25%">类别</th>
                    <th width="75%">内容</th>
                </tr>
                </thead>
                <tbody>
                <tr>
                    <td>uid</td>
                    <td>
                        <input type="text" name="uid" class="form-control" placeholder="" value="{{{uid}}}" disabled style="width: 150px" min="0">
                    </td>
                </tr>
                <tr>
                    <td>订单号</td>
                    <td>
                        <input type="text" name="order_sn" class="form-control" placeholder="" value="{{{order_sn}}}" disabled style="width: 150px" min="0">
                    </td>
                </tr>
                <tr>
                    <td>订单价格/元</td>
                    <td>
                        <input type="text" name="order_amount" class="form-control" placeholder="" value="{{{order_amount}}}" disabled style="width: 150px" min="0">
                    </td>
                </tr>
                <tr>
                    <td>第三方订单号</td>
                    <td>
                        <input type="text" name="third_order" class="form-control" placeholder="" value="{{{third_order}}}" disabled style="width: 150px" min="0">
                    </td>
                </tr>
                <tr>
                    <td>支付渠道</td>
                    <td>
                        <input type="text" name="channel" class="form-control" placeholder="" value="{{{orderChannelText channel}}}" disabled style="width: 150px" min="0">
                    </td>
                </tr>
                <tr>
                    <td>订单状态</td>
                    <td>
                        <input type="text" name="order_status" class="form-control" placeholder="" value="{{{orderStatusText order_status}}}" disabled style="width: 150px" min="0">
                    </td>
                </tr>
                <tr>
                    <td>生成时间</td>
                    <td >
                        <div class="form-inline">
                            <div class="form-group">
                                <input type="text" name="create_time" class="form-control timepicker2"  placeholder="" value="{{{dateConvNew create_time}}}" style="width: 180px">
                            </div>
                        </div>
                    </td>
                </tr>
                <tr>
                    <td>付款时间</td>
                    <td >
                        <div class="form-inline">
                            <div class="form-group">
                                <input type="text" name="pay_time" class="form-control timepicker2" placeholder="" value="{{{dateConvNew pay_time}}}" style="width: 180px">
                            </div>
                        </div>
                    </td>
                </tr>
                <tr>
                    <td>更新时间</td>
                    <td >
                        <div class="form-inline">
                            <div class="form-group">
                                <input type="text" name="update_time" class="form-control timepicker2" placeholder="" value="{{{dateConvNew update_time}}}" style="width: 180px">
                            </div>
                        </div>
                    </td>
                </tr>
                </tbody>
            </table>
        </div>
    </form>
    {{/.}}
</script>

<script type="text/template" id="editModal">
    <form>
        <div>
            <table class="table table-bordered">
                <thead>
                <tr>
                    <th width="25%">类别</th>
                    <th width="75%">内容</th>
                </tr>
                </thead>
                <tbody>
                <tr style="display:none;">
                    <td>uid</td>
                    <td>
                        <input type="text" name="auid" class="form-control" placeholder="" value="{{{uid}}}">
                    </td>
                </tr>
                <tr style="display:none;">
                    <td>订单号</td>
                    <td>
                        <input type="text" name="orderSn" class="form-control" placeholder="" value="{{{order_sn}}}">
                    </td>
                </tr>
                <tr>
                    <td>第三方订单号</td>
                    <td>
                        <input type="text" name="thirdOrder" class="form-control" placeholder="" value="" style="width: 150px" min="0">
                    </td>
                </tr>
                <tr>
                    <td>付款时间</td>
                    <td >
                        <div class="form-inline">
                            <div class="form-group">
                                <input type="text" name="payTime" class="form-control timepicker2" placeholder="" value="{{{dateConvNew pay_time}}}" style="width: 180px">
                            </div>
                        </div>
                    </td>
                </tr>
                <tr>
                    <td>操作</td>
                    <td style="text-align: center">
                        <button type="button" class="btn btn-info mySortPost">确定</button>
                    </td>
                </tr>
                </tbody>
            </table>
        </div>
    </form>
</script>

<!--template end-->


<!-- js placed at the end of the document so the pages load faster -->
<script src="<!--{eval echo register_static('js/jquery.js');}-->"></script>
<script src="<!--{eval echo register_static('js/bootstrap.min.js');}-->"></script>
<script src="<!--{eval echo register_static('js/pace.min.js');}-->"></script>
<script src="<!--{eval echo register_static('js/wow.min.js');}-->"></script>
<script src="<!--{eval echo register_static('js/jquery.nicescroll.js');}-->" type="text/javascript"></script>
<script src="<!--{eval echo register_static('js/jquery.app.js');}-->"></script>

<script src="<!--{eval echo register_static('js/handlebars-v4.0.5.js');}-->"></script>
<script src="<!--{eval echo register_static('js/handlebars-helper.js');}-->"></script>
<script src="<!--{eval echo register_static('layer/layer.js');}-->"></script>
<script src="<!--{eval echo register_static('laypage/laypage.js');}-->"></script>
<script src="<!--{eval echo register_static('laydate/laydate.js');}-->"></script>

<script src="<!--{eval echo register_static('assets/datatables/jquery.dataTables.min.js');}-->"></script>
<script src="<!--{eval echo register_static('assets/datatables/dataTables.bootstrap.js');}-->"></script>
<script src="<!--{eval echo register_static('assets/sweet-alert/sweet-alert.min.js');}-->"></script>
<script src="<!--{eval echo register_static('assets/sweet-alert/sweet-alert.init.js');}-->"></script>

<script src="<!--{eval echo register_static('js/sha1.js');}-->"></script>

<!-- Modal-Effect -->
<script src="<!--{eval echo register_static('assets/modal-effect/js/classie.js');}-->"></script>
<script src="<!--{eval echo register_static('assets/modal-effect/js/modalEffects.js');}-->"></script>

<script type="text/javascript">
    $(document).ready(function() {

        //编译模板
        var tp_tableCon = Handlebars.compile($('#tableCon').html());
        var tp_detialModal = Handlebars.compile($('#detailModal').html());
        var tp_editModal = Handlebars.compile($('#editModal').html());
        //var tp_myFindModal = Handlebars.compile($('#myFind').html());

        /*$('.myChoose').change(function () {
            _Where_.page = 1;
            var name = $(this).attr('name');
            $(this).val() != 'no' ?  _Where_.pay_status = $(this).val() : _Where_.pay_status = undefined;
                    
            RequestList();
        });*/

        $(document).off('#search').on('click','#search',function(){
            _Where_.page = 1;
            var uid = $('#inputYourText').val();
            var payStatus = $('#yourPayStatus').val();
            var business = $('#yourPayBusiness').val();
            uid != '' ? _Where_.uid = uid : _Where_.uid = undefined;
            payStatus != 'no' ? _Where_.pay_status = payStatus : _Where_.pay_status = undefined;
            business != 'no' ? _Where_.business = business : _Where_.business = undefined;
            RequestList();
        });

        $(document).off('click', '.detail').on('click', '.detail', function () {
            var id = $(this).data('id');
            var uid = $(this).data('uid');
            var index = layer.load();
            $.post(
                    '/admin.php?ac=order&op=detailTest',
                    {id:id, uid:uid},
                    function (r) {
                        layer.close(index);
                        if(r._code == 1){
                            var html = tp_detialModal(r.result);
                            layer.open({
                                type: 1,
                                title: '订单详情',
                                closeBtn: 1,
                                area:['550px', '650px'],
                                shadeClose: true,
                                content: html
                            });
                        }else{
                            layer.msg(r._msg, {icon: 0});
                        }
                    }
            );
        });

        $(document).off('click', '.update').on('click', '.update', function () {
            var data = {
                uid:$(this).data('uid'),
                order_sn:$(this).data('order')
            }
            var html = tp_editModal(data);
            layer.open({
                type: 1,
                title: '补单操作',
                closeBtn: 1,
                area:['390px', '320px'],
                shadeClose: true,
                content: html
            });
        });

        $(document).off('click', '.mySortPost').on('click', '.mySortPost', function () {
            var uid = $(this).parents().find('input[name="auid"]').val();
            var orderSn = $(this).parents().find('input[name="orderSn"]').val();
            var thirdOrder = $(this).parents().find('input[name="thirdOrder"]').val();
            var payTime = $(this).parents().find('input[name="payTime"]').val();
            var date = new Date(Date.parse(payTime.replace(/-/g, "/")));
            date = date.getTime();
            payTime = date / 1000;
            if(thirdOrder == ''){
                layer.msg('请输入第三方订单号!', {icon: 0});
                return;
            }
            if(payTime == ''){
                layer.msg('请选择付款时间!', {icon: 0});
                return;
            }
            var time = Date.parse(new Date());
            time = time/1000;
            var token = 'no token';
            hash = hex_sha1('UserAuth'+uid+'no token'+time);
            $.post(
                    'http://v2order.coin.ffrj.net/RemedyOrder/remedyOption?uid='+uid+'&order_sn='+orderSn+'&third_order=' + thirdOrder + '&pay_time='+payTime+'&time='+time+'&token='+token+'&hash='+hash ,
                    function (r) {
                        layer.closeAll();
                        if(r._code == 1){
                            layer.msg('操作成功', {icon: 1});
                            RequestList();
                        }else{
                            layer.msg(r._msg, {icon: 0});
                        }
                    }
            );
        });

        $(document).off('click', '.timepicker2').on('click', '.timepicker2', function () {
            laydate({
                format: 'YYYY-MM-DD hh:mm:ss',
                istime: true
            });
        });

        $(document).off('click', '.timepicker3').on('click', '.timepicker3', function () {
            laydate({
                format: 'YYYYMMDD',
                festival: true,
                istime: false
            });
        });

        /*$(document).off('change', '.actionChange').on('change', '.actionChange', function () {
            var NO = $(this).val();
            ActionChangeSelect(NO);
        });*/

        _Where_ = {page:1};
        //请求数据列表数据
        var RequestList = function () {
            where = _Where_;
            if(typeof where == 'undefined')where = {};
            var index = layer.load();
            $.post(
                    '/admin.php?ac=order&op=listTest',
                    where,
                    function (r) {
                        if (r._code == 1){
                            var html = tp_tableCon(r.result);
                            $('#tbody').html(html);
                            laypage({
                                cont: $('.pageCon'), //容器。值支持id名、原生dom对象，jquery对象。【如该容器为】：<div id="page1"></div>
                                pages: 100, //通过后台拿到的总页数
                                curr: _Where_.page || 1, //当前页
                                jump: function(obj, first){ //触发分页后的回调
                                    if(!first){ //点击跳页触发函数自身，并传递当前页：obj.curr
                                        _Where_.page = obj.curr;
                                        RequestList();
                                    }
                                }
                            });
                        }else{
                            layer.msg(r._msg, {icon: 0});
                        }
                        layer.close(index);
                    }
            );
        }
        RequestList();

    });

</script>
</body>
</html>
